package com.bocloud.cmp.dao.app.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import com.bocloud.cmp.dao.app.ApplicationOpenshiftClusterInfoDao;
import com.bocloud.cmp.entity.app.resource.ApplicationOpenshiftClusterInfo;
import com.bocloud.common.utils.ListTool;
import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.BasicDao;

/**
 * 
 * @author zjm
 * @date 2017年3月30日
 */
@Repository
public class ApplicationOpenshiftClusterInfoDaoImpl extends BasicDao implements ApplicationOpenshiftClusterInfoDao {

	@Override
	public boolean saveApplicationOpenshiftClusterInfo(ApplicationOpenshiftClusterInfo applicationOpenshiftClusterInfo)
			throws Exception {
		return this.baseSaveEntity(applicationOpenshiftClusterInfo);
	}

	@Override
	public boolean deleteApplicationOpenshiftClusterInfo(
			ApplicationOpenshiftClusterInfo applicationOpenshiftClusterInfo) throws Exception {
		return this.baseDelete(applicationOpenshiftClusterInfo);
	}

	@Override
	public ApplicationOpenshiftClusterInfo getApplicationOpenshiftClusterInfo(Long appId)
			throws Exception {
		String sql = "select * from application_openshift_cluster_info aoc "
				+ "where aoc.application_id = :appId";
		Map<String, Object> params = MapTools.simpleMap("appId", appId);
		List<Object> list = this.queryForList(sql, params, ApplicationOpenshiftClusterInfo.class);
		if (ListTool.isEmpty(list)) {
			return null;
		}
		return (ApplicationOpenshiftClusterInfo) list.get(0);
	}

	@Override
	public List<ApplicationOpenshiftClusterInfo> getAppClusterInfo(Long appClusterId) throws Exception {
		String sql = "select * from application_openshift_cluster_info aoc "
				+ "where aoc.openshift_cluster_id = :appClusterId";
		Map<String, Object> params = MapTools.simpleMap("appClusterId", appClusterId);
		List<Object> list = this.queryForList(sql, params, ApplicationOpenshiftClusterInfo.class);
		List<ApplicationOpenshiftClusterInfo> result = new ArrayList<>();
		for (Object object : list) {
			result.add((ApplicationOpenshiftClusterInfo) object);
		}
		return result;
	}
}
